// pages/shop_in/shop_in.js
const util = require('../../utils/util.js');
import { mchPosts, getIndustryList} from '../../api/api.js';
var me = require("../../utils/method.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parameter: {
      'navbar': '1',
      'return': '1',
      'title': '公司入驻'
    },IMG_URL:'http://try11.jiaodaoren.com/zhusiyao/zhenyangyou/',
    MXH_IMG_URL: 'http://try11.jiaodaoren.com/zhusiyao/meixihujiancaicheng/',

    imageList: [], //评价图片列表
    /**后端所需参数 */
    business_all: [],
    agree_entry_rules: true,  //默认同意协议,
    sexList: [{
      name: '1',
      value: '男',
      checked: true
    },
    {
      name: '2',
      value: '女',
      checked: false
    }
    ], //性别
    industryList:[],
    zzList: [{
      name: '1',
      value: '在线教育',
      checked: false
    },
    {
      name: '2',
      value: '工程施工',
      checked: false
    },
    {
      name: '3',
      value: '移动互联网',
      checked: false
    }
    ],

    rzList: [{
        name: '1',
        value: '未融资',
        checked: false
      },
      {
        name: '2',
        value: '天使轮',
        checked: false
      },
      {
        name: '3',
        value: 'A轮',
        checked: false
      },
      {
        name: '4',
        value: 'B轮',
        checked: false
      },
      {
        name: '5',
        value: 'C轮',
        checked: false
      },
       {
        name: '6',
        value: 'D轮及以上',
        checked: false
      },
      {
        name: '7',
        value: '已上市',
        checked: false
      },
      {
        name: '8',
        value: '不需要融资',
        checked: false
      }

    ],


    rsList: [{
      name: '1',
      value: '0-20人',
      checked: false
    },
    {
      name: '2',
      value: '20-99人',
      checked: false
    },
    {
      name: '2',
      value: '100-499人',
      checked: false
    },
    {
      name: '3',
      value: '500-999人',
      checked: false
    },
      {
        name: '4',
        value: '1000-9999人',
        checked: false
      },
      {
        name: '4',
        value: '10000人以上',
        checked: false
      }
    ],

    hx_Array_brand: [0],//默认显示一个,行业的数组长度
    hx_Input_text_brand: [],  /*当前行业的值 */
    showZZModal:false,
    zzText:'',
    rzText: '',
    rsText: '',
    zzTextId:0,
    showRZModal: false,
    showRSModal: false,
    mch:[],
    mch_license:[],
    industry_list:[],
  },
  /**设置全局input的name值 */
  input_name:function(e){
    // var key=e.currentTarget.dataset.key;
    // var value=e.detail.value;
    // var mch=this.data.mch;
    // this.setData({
    //   'mch.name':value
    // })
    var that=this;
    // this.setData({ that.updateValue(e)});
  },
  /**
   * 上传文件
   * 
  */
  uploadpic: function () {
    var that = this;
    util.uploadImageOne('upload/image', function (res) {
      that.data.mch_license.push(res.data.url);
      that.setData({ mch_license: that.data.mch_license     });
    });
  },

  /**
   * 删除图片
   * 
  */
  DelPic: function (e) {
    var index = e.target.dataset.index, that = this;
    that.data.mch_license.splice(index, 1);
    that.setData({ mch_license: that.data.mch_license });
  },
  applySubmit:function(e){
    var data=e.detail.value,that=this;
    data['zhuyin_name']=this.data.zzText;
    data['financing_name'] = this.data.rzText;
    data['person_name'] = this.data.rsText;
    data['mch_license'] = this.data.mch_license;
    data['hy_id'] = this.data.zzTextId;
    if(data['hy_id']==0){
      me.urlToast('行业不能为空!', '', 1000, 0);
    }
    mchPosts(data).then(res => {
      console.log('res的值',res);
      if(res.status==200){
        console.log('执行了1');
        me.urlToast('入驻成功!', '/pages/index/index', 1000, 0, 1);
      }else{
        console.log('执行了2');
        me.urlToast('入驻失败,请重试!', '/pages/index/index', 1000, 0,1);
      }
    }).catch(err => {
      that.setData({ loading: false, loadTitle: "加载更多" });
    })
  },
  updateValue(e) {
    let key = e.currentTarget.dataset.key;
    let nameMap = {};
    nameMap[key] = e.detail && e.detail.value;
    return nameMap
  },
  //打开政治面貌选择弹窗
  showZZPopup() {
    this.setData({
      showZZModal: true
    });
  },
  //改变政治面貌
  handleChangeZZ(e) {
    let text = e.detail.value, Attr = this.data.industryList, that = this;
    Attr.forEach(item => {
      if (item.cate_name == text) {
        that.setData({
          'zzTextId': item.id
        })
      }
    });
    this.setData({
      zzText: e.detail.value,
      showZZModal: false
    })
  },
  //关闭政治面貌选择弹窗
  onCloseZZModal() {
    this.setData({
      showZZModal: false
    });
  },


  //打开融资选择弹窗
  showRZPopup() {
    this.setData({
      showRZModal: true
    });
  },
  //改变政治面貌
  handleChangeRZ(e) {
    let text = e.detail.value, Attr = this.data.rzList, that = this;
    Attr.forEach(item => {
      if (item.value == text) {
        that.setData({
          'rzTextId': item.name
        })
      }
    });
    this.setData({
      rzText: e.detail.value,
      showRZModal: false
    })
  },
  //关闭政治面貌选择弹窗
  onCloseRZModal() {
    this.setData({
      showRZModal: false
    });
  },





  //打开融资选择弹窗
  showRSPopup() {
    this.setData({
      showRSModal: true
    });
  },
  //改变政治面貌
  handleChangeRS(e) {
    let text = e.detail.value, Attr = this.data.rsList, that = this;
    Attr.forEach(item => {
      if (item.value == text) {
        that.setData({
          'rsTextId': item.name
        })
      }
    });
    this.setData({
      rsText: e.detail.value,
      showRSModal: false
    })
  },
  //关闭政治面貌选择弹窗
  onCloseRSModal() {
    this.setData({
      showRSModal: false
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getIndustryList();
  },

  getIndustryList: function () {
    var that = this;
    getIndustryList().then(res => {
      that.setData({
        industryList: res.data.industryList
      });
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})